package practice_list;

/**
 * Created with Intellij JDEA
 * Description:
 * User:
 * Date:2022-03-17
 * Time:18:16
 */
public class 两数相加 {
        public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
            ListNode l3 = new ListNode(0);
            ListNode cur = l3;
            int count = 0;
            while (l1 != null || l2 != null || count != 0) {
                if (l1 != null ) {
                    count += l1.val;
                    l1 = l1.next;
                }
                if (l2 != null) {
                    count += l2.val;
                    l2 = l2.next;
                }

                cur.next = new ListNode(count % 10);
                cur = cur.next;
                count = count / 10;
            }
            return l3.next;
        }
}
